package com.jrfid.smartcabinet.demo.ui.setting

import android.app.Application
import android.view.View
import androidx.databinding.ObservableBoolean
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.navigation.NavController
import com.blankj.utilcode.util.AppUtils
import com.jrfid.smartcabinet.demo.R
import com.jrfid.smartcabinet.demo.base.BaseViewModel
import com.mc.enjoysdk.McHome
import com.mc.enjoysdk.McSystemUi

class SettingViewModel(application: Application, navController: NavController) : BaseViewModel(application, navController) {

    val showLogoutBtn = ObservableBoolean(true)
    val showClearDialog = MutableLiveData(false)
    val showOpenTheDoorDialog = MutableLiveData(false)

    fun onClickBackBtn(view: View) {
        navController.navigateUp()
    }

    fun onClickLogoutBtn(view: View) {
        navController.navigate(R.id.action_settingFragment_to_loginFragment)
    }

    fun onClickMenuBtn(view: View, position: Int) {
        when (position) {
            0 -> {
                //添加账号密码
                navController.navigate(R.id.addAccountFragment)
            }
            1 -> {
                //添加指静脉
                navController.navigate(R.id.addFingerFragment)
            }
            2 -> {
                //添加ic卡
                navController.navigate(R.id.addNFCFragment)
            }
            3 -> {
                //添加人脸
                navController.navigate(R.id.addFaceFragment)
            }
            4 -> {
                //柜体设置
                navController.navigate(R.id.cabinetConfigFragment)
            }
            5 -> {
                //清除数据
                showClearDialog.value = true
            }
            6 -> {
                //开门
                showOpenTheDoorDialog.value = true
            }
            7 -> {
                //退出APP
                McSystemUi.getInstance(getApplication()).temporarilySwitchNavigation(true)
                McSystemUi.getInstance(getApplication()).temporarilySwitchStatusBar(true)
                McHome.getInstance(getApplication()).startRawLauncher()
                AppUtils.exitApp()
            }
        }
    }
}